/**
 * Created by sun on 2016/8/4.
 */
define(function(require) {
	var app = require('/../js/app');
	require('ui-table');


	var toastr =require('toastr');
	app.useModule("ui.table");


	var datepicker = require('datepicker');
	app.controller('account_cashCtrl', ['$scope', '$http','$filter',
		function($scope, $http,$filter) {
			$scope.ctrlScope=$scope;
			$scope.orderParams = {
				url: "/admin/accountcash/list"
			};
			datepicker($scope);
			$scope.getShow=function(parm){
				$http({
					method: 'POST',
					url: "/admin/accountcash/statCashAmount",
					data:parm,
				}).success(function(data) {
					console.info(data);
					$scope.show=data;
				}).error(function(data) {});
			}
			$scope.getShow();

			//创建
			$scope.addOrderModal = function() {
				$scope.orderModal = !$scope.orderModal;
			};

			//查询订单
			$scope.openCheckModal= function (orderId,amount) {
				$scope.add={};
				$scope.add.amount=amount;
				$scope.add.orderId=orderId;
				$scope.checkModal = !$scope.checkModal;
				$http({
					method: 'POST',
					url: "/admin/order/orderSearch",
					data:{orderId:orderId}
				}).success(function(data) {
					if(data.respSubCode=='000000'){
						if(data.status == 'S'){
							$scope.add.respSubdes='成功';
							$scope.add.status='S';

						}else if(data.status == 'I'){
							$scope.add.respSubdes='处理中';
							$scope.add.status='';
						}else if(data.status == 'F'){
							$scope.add.respSubdes='失败';
							$scope.add.status='F';
						}
					}else if(data.respSubCode=='000002'){
						$scope.add.respSubdes='查询失败'
					}else if(data.respSubCode=='100000'){
						$scope.add.respSubdes='参数校验失败'
					}else if(data.respSubCode=='200005'){
						$scope.add.respSubdes='订单不存在';
						$scope.add.status='F';
					}else{
						$scope.add.respSubdes='服务器繁忙'
					}

					$scope.addItem= function () {

						$http({
							method: 'POST',
							url: "/pay/notice/withdraw",
							data:$scope.add
						}).success(function(data) {
							$scope.add={};
							if(data.result=='success'){
								toastr.success('补单成功');
								$scope.checkModal = !$scope.checkModal;
							}else{
								toastr.error(data.messageText)
							}

						}).error(function(data) {});
					}

				}).error(function(data) {});
			};

			//全局查询
			$scope.search = function() {
				$scope.ctrlScope.itemsearch.beginDateTime=$scope.ctrlScope.itemsearch.beginDateTimex;
				$scope.ctrlScope.itemsearch.endDateTime=$scope.ctrlScope.itemsearch.endDateTimex;
				$scope.ctrlScope.itemsearch.beginDateTime=$filter('date')($scope.ctrlScope.itemsearch.beginDateTime,'yyyy-MM-dd');
				$scope.ctrlScope.itemsearch.endDateTime=$filter('date')($scope.ctrlScope.itemsearch.endDateTime,'yyyy-MM-dd');
				//表格查询参数设置
				$scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;

				var parm =$scope.ctrlScope.itemsearch;
				$scope.getShow(parm);
				//表格刷新
				$scope.orderParams.reload();
			};

			//全局查询重置
			$scope.reset=function(){
				$scope.ctrlScope.itemsearch={};
				$scope.orderParams.ajaxParam={};
				$scope.orderParams.reload();
				$scope.getShow();
			};

			//提现通过
			//$scope.modifyModal = function(orderNo,cashStatus) {
			//	if (confirm("确认提现通过?")) {
			//		var parm={orderNo:orderNo,oldStatus:cashStatus,newStatus:1};
			//		$scope.review(parm);
			//	} else {
			//		return;
			//	}
			//};
			////提现不通过
			//$scope.deleteModal = function(orderNo,cashStatus) {
			//	if (confirm("确认提现不通过?")) {
			//		var parm={orderNo:orderNo,oldStatus:cashStatus,newStatus:0};
			//		$scope.review(parm);
			//	} else {
			//		return;
			//	}
			//};
			$scope.review = function(parm) {
				$http({
					method: 'POST',
					url: "/admin/accountcash/updateStatus",
					data:parm,
				}).success(function(data) {
					console.info(data);
					$scope.orderParams.reload();
				}).error(function(data) {});
			};
			//导出
			$scope.download=function(){
				var params=$scope.ctrlScope.itemsearch;
				$http.post("/admin/accountcash/excel/accountCash",params)
					.success(function (data){
						console.info(data);
						if(data.result=="success"){
							window.open(data.file);
						}else{
							toastr.error("导出失败");
						}
					}).error(function(data){

					});
			};

		}
	]);


});